package com.qs.javame.thread1028.future;

import java.util.concurrent.*;

public class TestFuture {
    public static void main(String[] args) {
        ExecutorService executorService = Executors.newCachedThreadPool();
        Future<Integer> future = executorService.submit(new AddNumberTask());
        System.out.println(Thread.currentThread().getName() + "--正在执行。。。");

        try {
            Integer result = future.get();
            System.out.println("result=" + result);
        } catch (InterruptedException | ExecutionException e) {
            e.printStackTrace();
        }

        executorService.shutdown();
    }
}


class AddNumberTask implements Callable<Integer>{

    @Override
    public Integer call() throws Exception {
        System.out.println("==>>execute call()");
        Thread.sleep(5000);
        return 5000;
    }
}